package com.maas.util.mybatis.jpa.littlenb.support.template.select;

import com.littlenb.mybatisjpa.support.template.SqlTemplate;
import com.littlenb.mybatisjpa.util.PersistentUtil;
import com.maas.util.mybatis.jpa.littlenb.support.constant.JpaConstant;

import java.lang.reflect.Field;

/**
 * <p>
 * SelectOrderBySqlTemplate
 * </p>
 *
 * @author zxm
 * @date 2021/08/04 16:18
 * @since 2021/08/04 16:18
 */
public class SelectOrderBySqlTemplate  implements SqlTemplate {
    @Override
    public String parseSQL(Class<?> type) {
        return "";
    }
    public String parseSQL(Class<?> type,String order) {
        Field[] fieldArr = PersistentUtil.getDeclaredFields(type);
        Field idField  = PersistentUtil.getIdField(type);
        if(JpaConstant.DEF_ID_ORDER.equals(order) && !"id".equals(idField.getName()) ){
            order =order.replace("id",PersistentUtil.getColumnName(idField));
        }
        String  orderBy =" order by " +order;
        return orderBy;
    }
}
